using System;
using System.Xml;
namespace Net35.Xrm.Sdk.Client
{
	public sealed class XrmBinding : System.ServiceModel.Channels.CustomBinding
	{
		private System.ServiceModel.Channels.TransportBindingElement _transportElement;
		private System.ServiceModel.Channels.MtomMessageEncodingBindingElement _mtomMessageEncodingElement;
		private System.ServiceModel.Channels.TextMessageEncodingBindingElement _textMessageEncodingElement;
		public int MaxBufferSize
		{
			get
			{
				System.ServiceModel.Channels.HttpTransportBindingElement httpTransportBindingElement = this._transportElement as System.ServiceModel.Channels.HttpTransportBindingElement;
				if (httpTransportBindingElement != null)
				{
					return httpTransportBindingElement.MaxBufferSize;
				}
				return -1;
			}
			set
			{
				System.ServiceModel.Channels.HttpTransportBindingElement httpTransportBindingElement = this._transportElement as System.ServiceModel.Channels.HttpTransportBindingElement;
				if (httpTransportBindingElement != null)
				{
					httpTransportBindingElement.MaxBufferSize = value;
				}
				if (this._mtomMessageEncodingElement != null)
				{
					this._mtomMessageEncodingElement.MaxBufferSize = value;
				}
			}
		}
		public long MaxReceivedMessageSize
		{
			get
			{
				if (this._transportElement != null)
				{
					return this._transportElement.MaxReceivedMessageSize;
				}
				return -1L;
			}
			set
			{
				if (this._transportElement != null)
				{
					this._transportElement.MaxReceivedMessageSize = value;
				}
			}
		}
		public XmlDictionaryReaderQuotas ReaderQuotas
		{
			get
			{
				if (this._textMessageEncodingElement != null)
				{
					return this._textMessageEncodingElement.ReaderQuotas;
				}
				if (this._mtomMessageEncodingElement != null)
				{
					return this._mtomMessageEncodingElement.ReaderQuotas;
				}
				return null;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException("value");
				}
				if (this._mtomMessageEncodingElement != null)
				{
					value.CopyTo(this._mtomMessageEncodingElement.ReaderQuotas);
				}
				if (this._textMessageEncodingElement != null)
				{
					value.CopyTo(this._textMessageEncodingElement.ReaderQuotas);
				}
			}
		}
		public override string Scheme
		{
			get
			{
				if (this._transportElement == null)
				{
					return string.Empty;
				}
				return this._transportElement.Scheme;
			}
		}
		internal XrmBinding(System.ServiceModel.Channels.Binding binding) : base(binding)
		{
			if (binding == null)
			{
				throw new ArgumentNullException("binding");
			}
			this.Initialize();
		}
		private void Initialize()
		{
			this._transportElement = base.Elements.Find<System.ServiceModel.Channels.TransportBindingElement>();
			this._mtomMessageEncodingElement = base.Elements.Find<System.ServiceModel.Channels.MtomMessageEncodingBindingElement>();
			this._textMessageEncodingElement = base.Elements.Find<System.ServiceModel.Channels.TextMessageEncodingBindingElement>();
		}
	}
}
